<?php
/**
 * Instead of putting each step on a separate page, each step will post back to this page and be
 * processed in the next step if it passes the previous step.
 */

define("ROOTDIR", dirname(__FILE__)); // Global Constant of root directory

require_once(ROOTDIR."/include/database/class.InstallAndUpgradeQueries.php");
require_once(ROOTDIR."/config/class.Config.php");

$config = new Config();
$installAndUpgrade = new InstallAndUpgradeQueries();

$installAndUpgrade->setDbHost($config->dbHostName);
$installAndUpgrade->setDbUser($config->dbUserName);
$installAndUpgrade->setDbPass($config->dbPassword);
$installAndUpgrade->setDbase($config->dbName);

$complete = false;

if(isset($_POST['submit'])) {
  $installAndUpgrade->createConnection();
  $installAndUpgrade->connectToDatabase();
  
  $upgradeVersion = $_POST['upgradeVersion'];

  // Upgrade from Version 2.2 to Version 3.0
  if($upgradeVersion == "22to30") {
    $installAndUpgrade->upgradeTwoPointTwoToThree();
  }

  $complete = true;
}
?>


<?php
/*************************************************
 * Start upgrade form
 *************************************************/
if(!$complete) {
?>
<h1>Global Ban Upgrade</h1>
<p>Both the install.php and upgrade.php files will be deleted after a successful upgrade!</p>
<p>Select the upgrade type you wish to perform!</p>

<form action="upgrade.php" method="post">
  Upgrade Type: <select name="upgradeVersion">
                  <option value="22to30" selected>2.2 to 3.0</option>
                </select>
  <input type="submit" name="submit" value="Upgrade!">
</form>

<?php
}
/*************************************************
 * End upgrade form
 *************************************************/
?>


<?php
/*************************************************
 * Upgrade COMPLETE
 *************************************************/
if($complete) {
?>
<script type="text/javascript">
window.location = "upgradeComplete.php"
</script>
<?php
}
/*************************************************
 * End Upgrade COMPLETE
 *************************************************/
?>
